Skip to content

Answer a Bot that stops its own run to ask before it uses a tool - #2618

Open
mme wants to merge 5 commits into
mainfrom
mme/bot-approval-card
Open

mme wants to merge 5 commits into
mainfrom
mme/bot-approval-card

Conversation

@mme

@mme mme commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Split out of #2326 so it can merge on its own. Two commits:

  1. A Bot that stops its own run to ask can be answered. A Bot connected by its address can pause a run on an AG-UI interrupt of its own, as a harness does before it runs one of its own tools. The server already passes that interrupt and its answer through (endpointResume); the app showed nothing, and the agent then refused every later run. The conversation now shows a card with the tool and its arguments and Allow / Don't allow. An interrupt that is not a yes or no gets "Carry on without it", which cancels it.

     <ChannelChat>
       <ConversationAllowances />
    +  <BotApprovalNotice />        # only interrupts the server does not own
    +    botRaisedInterrupts()      # app/src/lib/copilot/bot-raised-interrupts.ts
    +    copilotkit.runAgent({ agent, resume })
       <HandoffResumeNotice />
  2. A single-user OpenBot in a container answers the page's deployment question. Asked without cookies it said 403 on every page, so the release check and attachment limits were missing. The page asks once more with its cookies. The first, refused request still shows in the console.

Where it runs

  • New state that outlives a request? None. The card reads the interrupts the AG-UI agent in the page already holds.
  • What happens on the second replica? Nothing new on the server. The answer travels as the next run's resume, on the path a run already takes.
  • Anything serialised? No.
  • Anything fanned out to a browser? No new path. The interrupt arrives with the run's events as before.
  • New listener, port, or schedule? No.

Boundary and audit

  • Every acting call still goes through the gateway: resolve, decide, audit, then act.
  • New refusals and new failures each write a row.
  • Nothing new is trusted from the client that the server can resolve itself.

The two unticked boxes need a reviewer's call. The approval the card answers is about the Bot's own tool, run inside the Bot's process. It never went through the gateway, and Allow or Don't allow writes no audit row. This PR does not change that; it makes the question answerable.

API and database

  • This changes nothing under api/, no app's requests, no database change and no release-policy.json.

Changelog

Bots.

  • A Bot that stops to ask before it uses a tool can be answered. A Bot connected by its address can pause its own run to ask, as a harness does before it runs one of its own tools. The conversation now shows what the Bot wants to use and with what, with Allow and Don't allow; a wait that is not a yes or no can be let go. Before, nothing showed and the conversation was stuck: every later message was refused until the wait was answered.

One container.

  • A single-user OpenBot in a container tells its browser about the deployment. It refused the page's first question about the deployment on every page, so the release check and attachment limits were missing. The page now asks once more as the browser that was let in.

Proof

On this branch:

  • bun run typecheck in app: clean. biome lint on the touched files: clean.
  • bun test tests/bot-raised-interrupts.test.ts tests/second-organization.test.tsx tests/failure-said.test.ts: 17 pass.

Earlier, on an older base, in a single-container OpenBot with this app build and an AWS Strands harness Bot connected by address, driven through the browser:

  • The card appears when the harness asks before shell; Allow runs the tool, Don't allow tells the Bot it was refused, and a follow-up message is answered either way.
  • A reload with an approval waiting shows the card again.
  • OpenBot's own approval and the Bot's approval both work in one conversation.

Not done:

  • No screenshot or recording is attached.
  • On AWS Strands harness as a Bot #2326 the WebKit test shows "Thinking" within 200 ms ... from home failed once. I could not run it locally (it needs the CI's bun), so this PR's run is the check of whether the card is the cause.

@contextablemark contextablemark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d hold this for the resume fixes. I could answer a single active approval, but mixed waits and expired approvals still left the conversation stuck. A failed resume also gave me no feedback. I reproduced those cases in ChannelChat with the pinned SDK and a mocked runtime.

pending: readonly HeldInterrupt[],
approved: boolean,
): InterruptAnswer[] {
return botRaisedInterrupts(pending).map((interrupt) =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1. Mixed waits block the Bot’s answer. If the SDK holds one Bot interrupt and one OpenBot-owned interrupt, this drops the OpenBot ID from resume. AG-UI validates coverage against every pending ID before the run starts. I replayed both kinds together and clicked Allow. No request left the browser, and the card returned with no error. Please reconcile the OpenBot-owned wait before resuming the Bot’s wait, while keeping the OpenBot decision on its existing server path. The helper test covers the filtered payload, so please add a ChannelChat test that verifies the answer actually goes out.

): InterruptAnswer[] {
return botRaisedInterrupts(pending).map((interrupt) =>
asksForApproval(interrupt)
? { interruptId: interrupt.id, status: "resolved", payload: { approved } }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2. An expired approval can leave the conversation stuck. For a wait with an elapsed expiresAt, the pinned SDK rejects resolved before sending the request. I clicked both Allow and Don’t allow after replaying an expired approval. Neither sent a request, and there was no way to cancel the wait. Please check expiry when the person clicks and give them a way to continue with status: "cancelled".

setRunsInFlight((count) => count + 1);
try {
await whileObserved(agent, () =>
copilotkit.runAgent({ agent, resume }),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2. The resume skips the conversation’s run handling. With a mocked HTTP 503, the SDK reported an error but resolved the promise. The card’s catch never ran, and the conversation showed no failure. A successful resume showed the Bot’s reply in the transcript but sent no activity update for the conversation list. Please route this through the existing run tracking or cover both outcomes explicitly, including a visible error when the answer fails to send.

});
} catch (error) {
if (!(error instanceof ClientError) || error.status !== 403) throw error;
return getDeployment(DEPLOYMENT_ORGANIZATION, options);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the PR’s API checklist to call out this browser request change. A 403 from the anonymous deployment read now triggers a second GET with the browser’s cookies, using the existing endpoint and response contract.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants